#!/usr/bin/env python

#from __future__ import with_statement
import sys, math, linecache,  thread
import median

try:
 	import pygtk
  	pygtk.require("2.0")
except:
  	pass
try:
	import gtk
  	import gtk.glade
except:
	sys.exit(1)
	

def traceit(frame, event, arg):
    if event == "line":
        lineno = frame.f_lineno
        filename = frame.f_globals["__file__"]
        if filename == "<stdin>":
            filename = "glade.py"
        if (filename.endswith(".pyc") or
            filename.endswith(".pyo")):
            filename = filename[:-1]
        name = frame.f_globals["__name__"]
        line = linecache.getline(filename, lineno)
        print "%s:%s: %s" % (name, lineno, line.rstrip())

    return traceit


class Gui:

    def __init__(self):
        #Set the Glade file
        self.gladefile = "gui/gui.glade"  
        self.wTree = gtk.glade.XML(self.gladefile)
        
        self.window = self.wTree.get_widget("mainwindow")
        if (self.window):
            self.window.connect("destroy", self.destroy)

        self.entryIP = self.wTree.get_widget("entryIP")
        
        dic = { "on_buttonIP_clicked" : self.buttonIP_clicked,
            "on_quit1_activate" : gtk.main_quit }
        
        self.wTree.signal_autoconnect(dic)

    def destroy(klass, widget=None):
        gtk.main_quit()
        
    def buttonIP_clicked(self,w):
        print w.get_label(),":", self.entryIP.get_text()

if __name__ == "__main__":
	#sys.settrace(traceit)
	gui = Gui()
	gtk.main()
